from django.contrib import admin

from content.models import *

tiny_mce = (
                '/site-media/tiny_mce/tiny_mce.js',
                #'/site-media/tiny_mce/textareas.js',
                '/site-media/tiny_mce/config.js',
            )


class AdminSite(admin.AdminSite):
    pass

site = AdminSite()
class BandMemberInline(admin.TabularInline):
    model = BandMembership
    extra = 3
    
class ArtistAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}
    inlines = [BandMemberInline]
    class Media:
        js = tiny_mce
        
site.register(Artist, ArtistAdmin)

class AlbumAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}
    class Media:
        js = tiny_mce
        
site.register(Album, AlbumAdmin)

class TrackAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}
    class Media:
        js = tiny_mce
        
site.register(Track, TrackAdmin)

class PersonAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("name",)}
    class Media:
        js = tiny_mce
        
site.register(Person, PersonAdmin)


class BandMembershipAdmin(admin.ModelAdmin):
    pass
        
site.register(BandMembership, BandMembershipAdmin)

class PostAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}
    class Media:
        js = tiny_mce
        
    # http://code.djangoproject.com/wiki/CookBookNewformsAdminAndUser
    def save_model(self, request, obj, form, change): 
        instance = form.save(commit=False)
        instance.user = request.user
        instance.save()
        form.save_m2m()
        return instance

site.register(Post, PostAdmin)

class PostCategoryAdmin(admin.ModelAdmin):
    pass

site.register(PostCategory, PostCategoryAdmin)
